package com.passion.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * @program offline-e-commerce-data-warehouse
 * @Description 线程池配置类
 * @Author limeihua
 * @Date 2024/09/29 19:21
 * @Version 1.0
 */
@Configuration
public class ThreadPoolConfig {
    @Bean
    public ThreadPoolExecutor threadPoolExecutor() {
        return new ThreadPoolExecutor(
                5,
                20,
                5,
                TimeUnit.MINUTES,
                new LinkedBlockingQueue<>()
        );
    }

    /**
     * 获取固定大小线程池
     *
     * @return
     */
    @Bean
    public ExecutorService executorService() {
        return Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() - 1);
    }
}
